package com.example.zyfypt516wh.activities;

import androidx.appcompat.app.AppCompatActivity;

import android.graphics.PixelFormat;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.view.WindowManager;
import android.widget.MediaController;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.VideoView;

import com.example.zyfypt516wh.R;
import com.example.zyfypt516wh.common.Common;


public class ViewVideoActivity extends AppCompatActivity {
    private VideoView videoView;
    private TextView tvname;
    private String path="";
    private String name;
    @Override protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_view_video);

        //setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);//设置屏幕方向为横向

        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);//设置全屏
        getWindow().setFormat(PixelFormat.TRANSLUCENT);//透明

        videoView=findViewById(R.id.videoView);
        tvname=findViewById(R.id.tvname);

        name=getIntent().getStringExtra("name");//获取视频名字
        path= Common.BASEURL+"Uploads/video/video/"+getIntent().getStringExtra("videopath");//获取视频全路径

        Uri uri = Uri.parse(path);
        videoView.setVideoURI(uri);//设置视频路径
        videoView.setMediaController(new MediaController(this));//媒体播放控制工具 导包见上方
        //播放开始回调
        videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
            @Override public void onCompletion(MediaPlayer mediaPlayer) {
                Toast.makeText( ViewVideoActivity.this, "播放完成", Toast.LENGTH_SHORT).show();
            }
        });//播放完成回调
        videoView.requestFocus();// 让 VideoView 获取焦点
        videoView.start();//开始播放
        tvname.setText(name);//设置视频名字
    }
}